const App = getApp()
Page({
  data: {
    id: '',
    userinfo:''
  },

  onLoad: function (options) {
    console.log(options)
    let that = this
    that.setData({
      id: options.id
    })
    that.info()
  },
  info() {
    let that = this
    App.api.$http({
      url: 'user.coupon/detail',
      method: 'Post',
      data: {
        user_coupon_id: that.data.id
      }
    }, {}).then(res => {
      that.setData({
        ...res.data.order
      })
    })
  },
  Write(e) {
    console.log(e)
    let that = this
    let couponid = e.currentTarget.dataset.id
    wx.showModal({
      title: '提示',
      content: '此劵用于司机核销，您确认核销吗？',
      success(res) {
        if (res.confirm) {
          App.api.$http({
            url: 'user.coupon/consume',
            method: 'Post',
            data: {
              coupon_id: couponid
            }
          }, {}).then(res => {
            if (res) {
              App.api.$showSuccess(res.msg)
              wx.navigateBack()
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  onReady: function () {

  },
  onShow: function () {
    let that=this
    that.setData({
      userinfo:wx.getStorageSync('userInfo')
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})